package com.fenger.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @PackageName: com.fenger.servlet
 * @ClassName: LoginServlet
 * @Description:
 * @author: fang
 * @date: 2021/10/31 10:00
 */
@WebServlet(name = "logout", urlPatterns = "/logout")
public class LogoutServlet extends HttpServlet {
    public static final String TOKEN = "xx";
    public static final Set<String> usernameSet = new HashSet<>(Arrays.asList("zhangsan", "lisi"));

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie = new Cookie("token", "");
        cookie.setMaxAge(0);
        cookie.setPath("*/web_servlet_demo_Web_exploded*");
        resp.addCookie(cookie);
        req.getRequestDispatcher("page").forward(req, resp);
    }
}
